/**
 * @计算第二天
 *
 * @author	 wangshikun <wangshikun2010@gmail.com>
 * @copyright	(c) 2012 wangshikun <wangshikun2010@gmail.com>
 * @license	http://www.opensource.org/licenses/mit-license.php The MIT License
 * @package	default
 * @subpackage	default
 */

#include <stdio.h>
#include <stdbool.h>

struct date {
	int month;
	int day;
	int year;
};

int number(struct date d);
bool is_leap_year(struct date d);
struct date dateUpdate(struct date today);

int main(int argc, char *argv[]) {
	struct date thisDay, nextDay;

	printf("请输入一个日期：");
	scanf("%d %d %d", &thisDay.month, &thisDay.day, &thisDay.year);

	nextDay = dateUpdate(thisDay); 

	printf("Tomorrow's date is %d/%d/%.2d\n", nextDay.month, nextDay.day, nextDay.year % 100);

	return 0;
}

//计算下一日期的函数
struct date dateUpdate(struct date today) {
	struct date tomorrow; 
	
	//当前的天数不等于一个月的最后一天，计算明天
	if (today.day != number(today)) {
		tomorrow.day = today.day + 1;
		tomorrow.month = today.month;
		tomorrow.year = today.year;
		//年尾
	} else if (today.month == 12) {
		tomorrow.day = 1;
		tomorrow.month = 1;
		tomorrow.year = today.year + 1;
		//月末
	} else { 
		tomorrow.day = 1;
		tomorrow.month = today.month + 1;
		tomorrow.year = today.year;
	} 
	
	return tomorrow;
}

//查找一个月中日期数的函数
int number(struct date d) {
	int days;

	const int date[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	
	if (is_leap_year(d) == true && d.month == 2) {
		days = 29;
	} else {
		days = date[d.month - 1];
	}

	return days;

}

//判断年份是闰年还是平年
bool is_leap_year(struct date d) {
	bool year;

	if (d.year % 4 == 0 && d.year % 100 != 0 || d.year % 400 == 0) {
		year = true; //闰年
	} else {
		year = false; //平年
	}

	return year;
}
